
var util = require("../../util/util.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    formula:"",
    //云端存储地址
    song_site:'sdf',
    melody_site:'erjitr=2h',
    accompany_site:'',

    result:"",
    upload_result:"",

    typeArray:['lyric based','melody based','random new'],
  typeIndex:[0,1],
  cause: [' lab ', ' upload ', ' produce ', ' play '],
causeIndex: [0, 1,2,3],

    genderArray: ['男', '女'],
      genderIndex: 0,

      clientArray:['索尼','伯伯','苹果'],
      clientIndex: [0,1,2],

      debtor_id: '',
      type: 0, 
      causetype: '',

      data: util.getDate(),
      sigdata: '',
      duedata: '',

      asset_id: '',
      Price: '',  
      Count:'',

      ledger_id: ''
  },


        //a. 用户输入待处理歌词
        input: function(e){
                this.setData({
                        formula: e.detail.value
                }) 
                //console.log(e.detail.value+"input")              
        },
        //b. 按钮歌词计算开始，得{{}}
        calculate: function(){
                console.log(this.data.formula+"_formula to be calculated_sending")                     
                let algorithm = 'lyric_process'
                util.algorithm(algorithm,this.data.formula)
                wx.redirectTo({
                  url: '/pages/produce/L2M',
                })
        },

        //选择上传资料库，得服务器存储地址{{song_site}}
        upload:function(){             
                this.song_site= util.upload('song/')
        },

        //选择服务器地址{{song_site}}，得计算结果{{melody_site}}
        calculate_melody: function(){
                let algorithm = 'song_prime'
                let song_site = this.data.song_site

                console.log("composing a melody give the prime:"+ song_site)
                util.algorithm(algorithm, song_site)
                this.melody_site =''
        },
        //选择服务器地址{{melody_site}}的计算结果{{accompany_site}}
        calculate_accompaniment: function(){
                let algorithm = 'song_accompany'
               let melody_site = this.data.melody_site
               console.log("accompany the given melody: "+melody_site)

                util.algorithm(algorithm, melody_site)
                this.accompany_site =''
        },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this

  },

  inputLabel:function(e){
    var data = e.detail.value
    console.log(data);


  },
  savePersonInfo: function(e) {
    var data = e.detail.value

    console.log(data);
    wx.setStorage({
      key: 'bills',
      data: {
        debtor_id: data.debtor_id,
        type: data.type,
        causetype: data.causetype,


        sigdata: data.sigdata,
        duedata: data.duedata,

        asset_id: data.asset_id,
        Price: data.Price,  
        Count:data.Count,

        ledger_id: data.ledger_id
      },
      success: function(res){
        wx.showToast({
          title: '资料修改成功',
          icon: 'success',
          duration: 2000
        })
        setTimeout(function(){
          wx.navigateTo({
            url: '../bill/list'
          })
        },2000)
      }
    })
  },
  changeClient: function (e) {

    var clientIndex = e.detail.value
        console.log(e.detail.value+'传公司')
    if (clientIndex != "null") {
      this.setData({
        clientIndex: clientIndex,
        debtor_id: this.data.clientArray[this.data.clientIndex]
      })


    }
  },
})